package com.smzd.framework.system.dao;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.smzd.core.dao.AbstractDao;
import com.smzd.core.domain.Many2Many;
import com.smzd.core.mappers.IMapper;
import com.smzd.framework.system.domain.Module;
import com.smzd.framework.system.mappers.ModuleMapper;
import com.smzd.framework.utils.db.RPage;

@Component
public class ModuleDao extends AbstractDao<Module> {
    @Autowired
    private ModuleMapper mapper;

    @Override
    protected IMapper<Module> getMapper() {
        return mapper;
    }

    public RPage<Module> getMeetingModuleListByPage(RPage<Module> page) {
        preparePage(page);
        List<Module> elems = mapper.getMeetingModuleListByPage(page);
        page.setElems(elems);
        int total = mapper.getElemsCount(page);
        page.setTotalCount(total);
        completePage(page);
        return page;
    }

    public void saveMeetingModules(List<Many2Many> toAdd, List<Many2Many> toDel) {
        for (Many2Many add : toAdd) {
            mapper.insertMeetingModule(add);
        }
        for (Many2Many del : toDel) {
            mapper.removeMeetingModule(del);
        }
    }
}
